import axios,{type AxiosRequestConfig,type AxiosRequestHeaders,type RawAxiosRequestHeaders} from 'axios'
import nProgress from "nprogress";
import 'nprogress/nprogress.css'
import { useUserInfoStore } from '../store/userInfo';
const instance=axios.create({
  baseURL:'',
  timeout:50000
})

instance.interceptors.request.use((config:AxiosRequestConfig)=>{
  nProgress.start() //进度条开
  const userInfoStore = useUserInfoStore()
  if(userInfoStore.token){
    (config.headers).token = userInfoStore.token
  }
  return config
},error=>{
  nProgress.done() //进度条关
  return Promise.reject(error)
})
instance.interceptors.response.use((response)=>{
  nProgress.done()
  return response.data
 
  
},(error)=>{
  nProgress.done()
  return Promise.reject(error)
})
export default instance